// ordered_array.h -- Interface for creating, inserting, and deleting
// from ordered arrays.
// written for JamesM's kernel development tutorials.

#ifndef __ORDERED_ARRAY_H
#define __ORDERED_ARRAY_H

#include <common.h>
/**
	this array is insertion sorted - it always remains in a sorted state( between calls )
	it can store anything that can be cast to a void* -- so a u32int, or any pointer
**/
typedef void* type_t;
/** 
	A predicate should return nonzero if the first argument is less than the second. Else
	it should return zero.
**/
typedef s8int (*lessthan_predicate_t)(type_t, type_t);
typedef struct 
{
	type_t *array;
	u32int size;
	u32int max_size;
	lessthan_predicate_t less_than;
} ordered_array_t;

/**
	A standard less than predicate.
**/
s8int standard_lessthan_predicate(type_t a, type_t b);

/** 
	create an ordered array.
**/
ordered_array_t create_ordered_array(u32int max_size, lessthan_predicate_t less_than);
ordered_array_t place_ordered_array(void *addr, u32int max_size, lessthan_predicate_t less_than);

/**
	destroy an ordered array into oblivion
**/
void destroy_ordered_array(ordered_array_t *array);

/**
	add an item into the array
**/
void insert_ordered_array(type_t item, ordered_array_t *array);

/**
	lookup the item at index i
**/
type_t lookup_ordered_array(u32int i, ordered_array_t *array);

/** 
	Deletes the item at location i from teh array
**/
void remove_ordered_array(u32int i, ordered_array_t *array);

#endif //__ORDERED_ARRAY_H
